﻿using System.Collections.Generic;
using RAP.Framework.Libary.Utils;
using System.Collections;

namespace RAP.Framework.Libary.DomTemplateBuilder.Configuration
{
	/// <summary>
	/// 自定义属性集合
	/// </summary>
	public class AttributeCollection : Dictionary<string, object>
	{
		public new object this[ string key ]
		{
			get
			{
				if ( this.ContainsKey ( key ) )
				{
					return base[ key ];
				}
				return null;
			}
			set
			{
				base[ key ] = value;
			}
		}

		/// <summary>
		/// 将制定Key的属性转换成字符串
		/// </summary>
		/// <param name="key"></param>
		/// <returns></returns>
		public string ToString ( string key, string defaultValue = null )
		{
			return this[ key ].IsNullValue<string> ( defaultValue );
		}

		/// <summary>
		/// 将制定Key的属性转换成数字
		/// </summary>
		/// <param name="key"></param>
		/// <param name="defaultValue"></param>
		/// <returns></returns>
		public int ToInt32 ( string key, int defaultValue = 0 )
		{
			return this[ key ].ToInt32Value ( defaultValue );
		}

		/// <summary>
		/// 将制定Key的属性转换成键值对象
		/// </summary>
		/// <param name="key"></param>
		/// <param name="defaultValue"></param>
		/// <returns></returns>
		public IDictionary ToDictionary ( string key, IDictionary defaultValue = null )
		{
			return this[ key ].IsNullValue<IDictionary> ( defaultValue );
		}

		/// <summary>
		/// 将制定Key的属性转换成集合对象
		/// </summary>
		/// <param name="key"></param>
		/// <param name="defaultValue"></param>
		/// <returns></returns>
		public IList ToList ( string key, IList defaultValue = null )
		{
			return this[ key ].IsNullValue<IList> ( defaultValue );
		}
	}
}
